<template>
  <div class="bg">
    <!-- 时间搜索框 -->
    <!-- <searchTime
      @searchvalue="userSearch"
      :options="options"
      :selectBoolen="false"
      :selectTime="true"
    />-->

    <!-- 表格展示 -->
    <el-card class="card">
      <div slot="header">
        <el-row type="flex" justify="end">
          <el-col :span="2">
            <el-button type="success" @click="NewAdmin" size="small">新建管理员</el-button>
          </el-col>
        </el-row>
      </div>
      <!-- 表格展示 -->
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column prop="index" label="序号" width="100" align="center"></el-table-column>
        <el-table-column prop="adminAccount" label="管理员账号" align="center"></el-table-column>
        <el-table-column prop="adminPhone" label="手机号码" align="center"></el-table-column>
        <el-table-column prop="adminCreateTime" label="创建时间" align="center"></el-table-column>
        <el-table-column prop="roleStatus" label="状态" align="center">
          <template slot-scope="scope">
            <span>{{scope.row.adminStatus==1?'有效':'无效'}}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="lookAdmin(scope.row)">查看/编辑</el-button>
            <!-- <el-button type="danger" size="small" @click="adminDelet(scope.row)">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        background
        layout="total,  prev, pager, next, jumper"
        :total="total"
        :current-page="current"
        style="margin-top:24px"
        @current-change="currentpange"
      ></el-pagination>
    </el-card>
    <!-- 弹窗 -->

    <!-- <el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
      <dynamic />
    </el-dialog>-->
  </div>
</template>

<script>
import { export2Excel } from "@/components/commom.js";
import searchTime from "@/components/searchTime";
// import dynamic from "@/components/dynamic";
export default {
  components: {
    searchTime
    // dynamic
  },
  data() {
    return {
      value: "",
      value1: "",
      downloadLoading: false,
      tableData: [],
      total: 0,
      current: 1
    };
  },
  mounted() {
    this.roleAdminlist();
  },
  methods: {
    // 获取管理员列表
    roleAdminlist() {
      let params = {
        size: 10,
        current: this.current
      };
      this.$http.article.roleAdmin(params).then(res => {
        console.log("获取管理员列表", res);
        this.tableData = res.result.records;
        this.total = res.result.total;

        //显示每页展示的数量
        res.result.records.forEach((item, index) => {
          //res.data.data.list 表格数据     forEach为每一项添加数据
          item.index = index + 1 + (this.current - 1) * 10;
          // this.currentPage当前页  this.pageParams.size 每页显示多少    :page-sizes="[10,20,30,50]" 分页大小

          return item;
        });
      });
    },
    // 新建管理员
    NewAdmin() {
      console.log("新建管理员");
      this.$router.push("/home/newadmin");
    },

    // 分页操作
    currentpange(val) {
      console.log("获取管理员");
      this.current = val;
      this.roleAdminlist();
    },
    // 查看修改用户管理列表
    lookAdmin(val) {
      this.$router.push({
        path: "/home/newadmin",
        query: { adminId: val.adminId }
      });
      console.log("查看更多列表", val);
    },
    // 删除用户管理
    // adminDelet(val) {
    //   this.$http.article.adminDelete({ yjAdminId: val.adminId }).then(res => {
    //     console.log("删除用户管理", res);
    //     if (res.code == 200) {
       
    //           /*--------删除成功之后获取上一页的数据,避免是否为空--------*/

    //           //此时已经实现删除操作，所以total的值需要减size，Math.ceil是向上取整，保证始终大于等于0
    //           const totalPage = Math.ceil((this.total - 1) / 10);

    //           console.log("totalPage", totalPage);

    //           //将当前页码与删除数据之后的总页数进行比较，避免当前页码不存在
    //           const pagenum =
    //             this.current > totalPage ? totalPage : this.current;

    //           console.log("获取总条数", pagenum);

    //           //避免pagenum变为0
    //           this.current = pagenum < 1 ? 1 : pagenum;
    //           // 提示弹窗
    //           this.$message.success("删除成功!");
    //       this.roleAdminlist(1);
    //     } else {
    //       this.$message({
    //         message: res.msg,
    //         type: "error"
    //       });
    //     }
    //   });
    // }
  }
};
</script>

<style lang="scss" scoped>
.merchantData {
  display: flex;
  align-items: center;
  padding-top: 14px;
  .addmerchant {
    color: #409eff;
    font-size: 18px;
    font-family: Microsoft YaHei;
    font-weight: 400;
  }
  .merchantNum {
    color: #f23a3a;
    font-size: 18px;
    font-family: Microsoft YaHei;
    font-weight: 800;
  }
}

.clearfix {
  padding-bottom: 20px;
}
.bg {
  width: 100%;
  height: 100%;
  background-color: #f4f7fd;
}

.card {
  width: 98%;
  margin: 0 auto;
  margin-top: 10px;
}
</style>